Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Webhooks #1365

Merged
merged 58 commits into from
Mar 4, 2024

Conversation

andreas-marschke
Copy link
Collaborator

@andreas-marschke andreas-marschke commented Jul 26, 2023

Add support for Webhooks in Ansible-Semaphore

This MR adds support for Webhooks to trigger Ansible Templates and run Playbooks based on configuration given to a webhook that can be potentially received by semaphore.

Webhook Configuration

The change hereby presented adds a new item on the sidebar titled Webhooks, navigating here will present the user with a list of Webhooks being recognized by the system.

A webhook links to a template in Semaphore which will be run when the e webhook satisfied its extractor configuration and has succeeded all Matcher criteria.

Webhook Extractors

A webhook consists of 1 or more Webhook Extractors which in turn have 1 or more Matchers and Extracted Values

Webhook Matchers

A Matcher defines a characteristic of the webhook event being sent to the semaphore system where the system will read the request for its body or header data and match on fields presented in the webhook.

Consider the following Webhook posted to semaphore system:

POST /webhook HTTP/1.1
Host: semaphore.example.org
Content-Type: application/x-application-json

{
  "data": {
    "field1": "a",
    "field2": "b"
  }
}

A matcher may now select to parse the body JSON to retrieve for example data.field1
It may now try to :

  • test if a field value is equal
  • test if a field value is unequal
  • test if a field value contains a string

If all the Matchers for an extractor have been met the system will engage the extractor linked Webhook Extract Values

Extracted Value

An extracted value is any field selected from the webhook to turn into a variable on the template fields/values being passed to the playbook being run as part of the template attached to the webhook object.

Considering the previously described Webhook posted to semaphore system:

POST /webhook HTTP/1.1
Host: semaphore.example.org
Content-Type: application/x-application-json

{
  "data": {
    "field1": "a",
    "field2": "b"
  }
}

The extractvalue may now select data.field2 and assign it to VARIABLE_A which would be passed as configuration variable to the ansible-playbook run invoked by the template.

This way the system can augment the received data to provide it to the playbook being run.

Webhook execution

Upon receiving a Webhook that satisfied all matchers and has successfully extracted all the required values into variables, the system will attempt to trigger a run of a template, build or deployment.

@andreas-marschke
Copy link
Collaborator Author

@fiftin It would be awesome if you could help me get this over the line as I'm currently hitting some issues with boltdb and updating the objects. I believe part of this is due to the way the buckets are set up?

@andreas-marschke andreas-marschke marked this pull request as ready for review August 2, 2023 01:02
@andreas-marschke andreas-marschke changed the title DRAFT: Add Support for Webhooks Add Support for Webhooks Aug 2, 2023
@andreas-marschke
Copy link
Collaborator Author

@fiftin It is finally ready for review.

I will work on the merge conflicts sooner rather than later

@fiftin
Copy link
Collaborator

fiftin commented Aug 6, 2023

Hi @andreas-marschke

Thank you for your PR. I will help with it if I can.

@fiftin
Copy link
Collaborator

fiftin commented Aug 26, 2023

Working with the PR! Thank you!

@anardil
Copy link

anardil commented Aug 28, 2023

Hello,

Do you know when it will be available on the next version?

Thank you.

@andreas-marschke
Copy link
Collaborator Author

@fiftin I updated the PR with some UI polish and backend fixes for the boltdb version of it. I'm trying to figure out what's wrong on the CI, if you can help me figure this out, that would be cool.

Here are some screenshots:

Webhooks Main Page

Webhooks Main Page

Extractor View

Extractor View

Extractor Actual Configuration

Extractor Actual Configuration

@alex-grandson
Copy link

alex-grandson commented Jan 9, 2024

Sorry for stupid question, but could you please clearify for me one thing. As I understood these changes point to webhook to semaphore system, not for an external thing.
So, my question is do you have in plans to include external webhook functionality? For situations like after ansible play ends notificate some system in general with data about failure/success, hosts, maybe output optionally? For example, I have some cron-job playbook run and I want to "subscribe" for its runs.
I'll be very grateful for the answer
Thanks!

@andreas-marschke
Copy link
Collaborator Author

andreas-marschke commented Jan 9, 2024 via email

@fiftin fiftin merged commit 3ba035f into semaphoreui:develop Mar 4, 2024
4 checks passed
@andreas-marschke
Copy link
Collaborator Author

@fiftin Thank you for the support and help getting this over the line.
When do you plan on having the next release? I'm fine with a Beta so long as I have a container to run.

@arpanghosh8453
Copy link

is this feature available in the docker container yet?

@andreas-marschke
Copy link
Collaborator Author

andreas-marschke commented Mar 13, 2024 via email

@fiftin fiftin self-assigned this Mar 23, 2024
@fiftin fiftin added the feature label Mar 23, 2024
@tboerger
Copy link
Collaborator

tboerger commented May 6, 2024

On github it's #1816 :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants